package com.ruoyi.web.controller.Resource;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ResourceTable;
import com.ruoyi.system.service.IResourceTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资源Controller
 * 
 * @author ruoyi
 * @date 2024-04-18
 */
@RestController
@RequestMapping("/Resource/table")
public class ResourceTableController extends BaseController
{
    @Autowired
    private IResourceTableService resourceTableService;

    /**
     * 查询资源列表
     */
//    @PreAuthorize("@ss.hasPermi('system:table:list')")
    @GetMapping("/list")
    @Anonymous
    public TableDataInfo list(ResourceTable resourceTable)
    {
        startPage();
        List<ResourceTable> list = resourceTableService.selectResourceTableList(resourceTable);
        return getDataTable(list);
    }

    /**
     * 导出资源列表
     */
//    @PreAuthorize("@ss.hasPermi('system:table:export')")
    @Log(title = "资源", businessType = BusinessType.EXPORT)
    @Anonymous
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResourceTable resourceTable)
    {
        List<ResourceTable> list = resourceTableService.selectResourceTableList(resourceTable);
        ExcelUtil<ResourceTable> util = new ExcelUtil<ResourceTable>(ResourceTable.class);
        util.exportExcel(response, list, "资源数据");
    }

    /**
     * 获取资源详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:table:query')")
    @Anonymous
    @GetMapping(value = "/{resourceId}")
    public AjaxResult getInfo(@PathVariable("resourceId") Long resourceId)
    {
        return success(resourceTableService.selectResourceTableByResourceId(resourceId));
    }

    /**
     * 新增资源
     */
//    @PreAuthorize("@ss.hasPermi('system:table:add')")
    @Anonymous
    @Log(title = "资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResourceTable resourceTable)
    {
        return toAjax(resourceTableService.insertResourceTable(resourceTable));
    }

    /**
     * 修改资源
     */
//    @PreAuthorize("@ss.hasPermi('system:table:edit')")
    @Anonymous
    @Log(title = "资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResourceTable resourceTable)
    {
        return toAjax(resourceTableService.updateResourceTable(resourceTable));
    }

    /**
     * 删除资源
     */
//    @PreAuthorize("@ss.hasPermi('system:table:remove')")
    @Anonymous
    @Log(title = "资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{resourceIds}")
    public AjaxResult remove(@PathVariable Long[] resourceIds)
    {
        return toAjax(resourceTableService.deleteResourceTableByResourceIds(resourceIds));
    }
}
